﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GauntletFramework.SpriteManagment
{
    public class SpriteSheet
    {
        public SpriteSheet(Texture2D Sprites, int HorizontalCount, int VerticalCount)
        {
            this.Sprites = Sprites;
            this.HorizontalCount = HorizontalCount;
            this.VerticalCount = VerticalCount;
            HalfFrame = new Vector2((Sprites.Width / HorizontalCount) / 2f, (Sprites.Height / VerticalCount) / 2f);
        }

        public Texture2D Sprites;
        public int HorizontalCount;
        public int VerticalCount;
        public Vector2 HalfFrame;

        public Rectangle GetRectangle(int FrameIndex)
        {
            if (FrameIndex < 0 || FrameIndex >= HorizontalCount * VerticalCount)
                return new Rectangle(0, 0, Sprites.Width, Sprites.Height);

            return new Rectangle(Sprites.Width / HorizontalCount * (FrameIndex % HorizontalCount),
                                 Sprites.Height / VerticalCount * (FrameIndex / HorizontalCount),
                                 Sprites.Width / HorizontalCount,
                                 Sprites.Height / VerticalCount);
        }
    }
}
